﻿#region Using Statements

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;


#endregion

namespace BrickBreaker.Core
{
    public class BBText
    {
        #region VARIABLES

        private string text;
        private Vector2 position;
        //Local variables
        private Color activeColor, basicColor, selectedColor;
        private bool isTextActive;

        #endregion VARIABLES


        #region OBJECT CONSTRUCTION
        //
        /// <summary>
        /// Creates a text object. Text defaults to not being active.
        /// </summary>
        /// <param name="text">The string of text the text object will hold.</param>
        /// <param name="position">The position of the text object.</param>
        //Constructor..
        public BBText(string text, Vector2 position)
        {
            //this.font = new SpriteFont();
            //this.font = BBGlobalConfig.font;
            this.text = text;
            this.position = position;
            this.selectedColor = Color.Blue;
            this.basicColor = this.activeColor = Color.Black;
            isTextActive = false;
        }
        //
        /// <summary>
        /// Creates a text object. Text is active based on input.
        /// </summary>
        /// <param name="text">The string of text the text object will hold.</param>
        /// <param name="position">The position of the text object.</param>
        /// <param name="active">Should the text display or not></param>
        //Constructor..
        public BBText(string text, Vector2 position, Color color, bool active)
        {
            //this.font = new SpriteFont();
            //this.font = BBGlobalConfig.font;
            this.text = text;
            this.position = position;
            this.selectedColor = Color.Blue;
            this.basicColor = this.activeColor = color;
            isTextActive = active;
        }
        //
        #endregion OBJECT CONSTRUCTION


        #region PROPERTIES
        //
        public Vector2 Position
        {
            get { return position; }
            set { position = value; } 
        }

        //Size of Text
        public Vector2 Size
        {
            get { return BBGlobalConfig.font.MeasureString(text); }
        }

        //Track if Text Has Focus/Attention
        public bool Active
        {
            get { return isTextActive; }
            set { isTextActive = value; }
        }

        public string Text
        {
            get { return text; }
            set { text = value; }
        }

        //
        #endregion PROPERTIES


        #region PUBLIC METHODS

        /// <summary>
        /// Updates the text and it's color.  Call this in a spritebatch.Begin()/End() block.
        /// </summary>
        /// <param name="spriteBatch">Your spritebatch.  Make sure you have already called begin().</param>
        public void Update()
        {
            if (this.isTextActive && this.activeColor == this.basicColor)
            {
                this.activeColor = this.selectedColor;
            }
            else if (!this.isTextActive && this.activeColor == this.selectedColor)
            {
                this.activeColor = this.basicColor;
            }
        }// end Update()
        //
        /// <summary>
        /// Draws the text.  Call this in a spritebatch.Begin()/End() block.
        /// </summary>
        /// <param name="spriteBatch">Your spritebatch.  Make sure you have already called begin().</param>
        /// <param name="font">The font you want to use to draw this text.</param>
        public void Draw(SpriteBatch spriteBatch, SpriteFont font)
        {
            spriteBatch.DrawString(font, this.text, this.position, this.activeColor);
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            if (isTextActive)
            {
                spriteBatch.DrawString(BBGlobalConfig.font, this.text, this.position, this.activeColor);
            }
        }
        
        // end Draw()

        #endregion PUBLIC METHODS
    }//end class
}//end namespace
